﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using blackhouse.BlackApart.Data;
using blackhouse.BlackApart.Business.Apartments;
using blackhouse.BlackApart.Business.Reservations;

namespace blackhouse.BlackApart.Business.Calendar {
    public class DaApartmentCalendar : ICalendar {

        #region Fields

        private IReservationDataAccess iCalendarData;
        internal ImpApartmentCalendar instance;

        #endregion

        #region Properties

        public System.Collections.ObjectModel.ReadOnlyCollection<IWebReservation> Reservations {
            get { return this.instance.Reservations; }
        }

        public IApartment Apartment {
            get {
                return this.instance.Apartment;
            }
        }

        public DateTime FromDay { get { return this.instance.FromDay; } }

        public DateTime ToDay { get { return this.instance.ToDay; } }

        #endregion

        #region Constructors

        public DaApartmentCalendar(IReservationDataAccess data, IApartment apartment, DateTime startDate, DateTime endDate) {
            this.iCalendarData = data;
            this.instance = new ImpApartmentCalendar(apartment, startDate, endDate);
        }

        #endregion

        #region Methods

        //public IWebReservation CreateReservation() {
        //    this.CheckInstanceReservations();
        //    IWebReservation reservation = new DaWebReservation(this, this.iCalendarData);
        //    reservation.Apartment = this.Apartment;
        //    this.instance.AddReservation(reservation);
        //    return reservation;
        //}

        public int GetDayState(DateTime day) {
            this.CheckInstanceReservations();
            return this.instance.GetDayState(day);
        }

        private void CheckInstanceReservations() {
            if (this.instance.Reservations == null)
                this.instance.SetReservations(new DaWebReservation(this.iCalendarData).GetReservations(this, this.FromDay, this.ToDay));
        }

        #endregion

    }
}
